<?php
class UnitTestCase_Unfuddle_Api extends UnitTestCase_Unfuddle {

    public function setUp() {
    
        Mock::generate('Unfuddle_Auth');
    
    }
    
    public function testGetUriWithOnlySubdomain() {
    
        $api = new Unfuddle_Api('foo');
        $url = $api->getUri();
        $this->assertEqual($url, 'http://foo.unfuddle.com/api/v1');
    
    }
    
    public function testGetUriWithSubdomainAndSecure() {
    
        $api = new Unfuddle_Api('foo', true);
        $url = $api->getUri();
        $this->assertEqual($url, 'https://foo.unfuddle.com/api/v1');
    
    }
    
    public function testGetUriWithSubdomainAndSecureAndApiVersion() {
    
        $api = new Unfuddle_Api('foo', true);
        $api->setApiVersion(3);
        $url = $api->getUri();
        $this->assertEqual($url, 'https://foo.unfuddle.com/api/v3');
    
    }
    
    /**
     * The URI doesn't actually change when authenticated so this isn't necessary
     */
    public function testGetUriWithAuth() {
    
        $testauth = new MockUnfuddle_Auth();
        $testauth->setReturnValue('getUsername', 'username');
        $testauth->setReturnValue('getPassword', 'password');
        $api = new Unfuddle_Api('foo');
        $api->authenticate($testauth);
        $url = $api->getUri();
    
    }
    
    public function testSetOtherScheme() {
    
        $api = new Unfuddle_Api('foo');
        $api->setScheme('email');
        $this->assertEqual($api->getUri(), 'email://foo.unfuddle.com/api/v1');
    
    }
    
    public function testSetDomainAfterConstruct() {
    
        $api = new Unfuddle_Api(null);
        $this->assertEqual($api->getUri(), 'http://.unfuddle.com/api/v1');
        $api->setDomain('test');
        $this->assertEqual($api->getUri(), 'http://test.unfuddle.com/api/v1');
    
    }

}